package androidx.blogger.tasks;

import com.google.gwt.user.client.rpc.AsyncCallback;

import androidx.blogger.BloggerApplication;
import androidx.gdata.blogger.Blog;
import androidx.gdata.blogger.BlogEntry;
import androidx.util.GUITask;
import androidx.util.GUITaskQueue;
import androidx.util.ProgressIndicator;

public class PostBlogEntryTask implements GUITask {
	private Blog blog;
	private AsyncCallback<Blog> callback;
	private BlogEntry entry;

	public PostBlogEntryTask(Blog blog, BlogEntry entry, AsyncCallback<Blog> callback) {
		this.blog = blog;
		this.entry = entry;
		this.callback = callback;
	}
	
	public static void execute(ProgressIndicator progressIndicator, Blog blog, BlogEntry entry, AsyncCallback<Blog> callback) {
		GUITaskQueue.getInstance().addTask(progressIndicator
				, new PostBlogEntryTask(blog, entry, callback));
	}

	
	public void executeNonGuiTask() throws Exception {
		blog = BloggerApplication.getInstance().getServer().postBlogEntry(blog, entry);
	}
	
	public void after_execute() {
		callback.onSuccess(blog);
	}


	public void onFailure(Throwable t) {
		callback.onFailure(t);
	}

}
